import React from 'react';
import ReactDOM from 'react-dom';
import './06props.css'

function UserGreet(props){

  return(
 
   <h1>欢迎登陆</h1>
 
  )
 
 }
 
 function UserLogin(props){
 
  return(
 
   <h1>请先登录</h1>
 
  )
 
 }
 
 
 
 class PartentCom extends React.Component{
 
  constructor(props){
 
   super(props)

   this.state = {
    isLogin: true

   }
  }
 
  render(){
    let elemnet = null;
    if (this.state.isLogin) {
      elemnet = (<UserGreet></UserGreet>);

    }else{
      elemnet = (<UserLogin></UserLogin>);

    }

    return (
      <div>
        <h1>这是头部</h1>
        {elemnet}
        <h1>这是三元运算符的操作</h1>
        {this.state.isLogin?<UserGreet></UserGreet>:<UserLogin></UserLogin>}
        <h1>这是尾部</h1>
      </div>
    )

  }

 }
 
 

  ReactDOM.render(
    <PartentCom /> ,
    document.querySelector('#root')
  )

    // console.log(new Date()); 不会初始化
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA

